package com.asen.commons.core.base.enums;

import com.asen.commons.core.base.model.IntegerEnumEntry;
import com.asen.commons.core.base.IntegerEnum;
import io.swagger.annotations.ApiModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 单据状态
 *
 * @author Gary
 * @version 1.0
 * @date 2018-11-13
 */
@ApiModel("单据状态")
public enum BillStatusEnum implements IntegerEnum {

    /**
     * 新增
     */
    NEW(0, "新增"),

    SAVED(1, "已保存"),

    SUBMITED(2, "已提交"),

    AUDITED(3, "已审核"),

    AUDITING(4, "审批中"),

    EDITING(5, "修改中"),

    FINISHED(90, "已完结"),

    CANCELED(99, "已作废");

    private Integer value;

    private String desc;

    BillStatusEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    private static BillStatusEnum getBillStatusEnumByType(Integer type) {
        BillStatusEnum[] enums = BillStatusEnum.values();
        for (BillStatusEnum statusEnum : enums) {
            if (statusEnum.getValue().equals(type)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static String getDescByValue(Integer value) {
        BillStatusEnum mode = BillStatusEnum.getBillStatusEnumByType(value);
        return mode == null ? "" : mode.getDesc();
    }

    public static List<IntegerEnumEntry> getCommonStatusList() {
        List<IntegerEnumEntry> statusList = new ArrayList<>();
        List<BillStatusEnum> billStatusEnumList = Arrays.asList(BillStatusEnum.SAVED, BillStatusEnum.SUBMITED, BillStatusEnum.AUDITED);
        billStatusEnumList.forEach(a -> {
            IntegerEnumEntry entry = new IntegerEnumEntry();
            entry.setValue(a.getValue());
            entry.setDesc(a.getDesc());
            statusList.add(entry);
        });
        return statusList;
    }
}
